package com.jacky.ws.endpoints;

import jakarta.websocket.Session;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ConcurrentHashMap;

public class CustomerSessionManager {

    private static ConcurrentHashMap<String, Session> sessionMap = new ConcurrentHashMap<>();
    private static ConcurrentHashMap<String/*sessionId*/, String/*userIdentify*/> sessionIdMap = new ConcurrentHashMap<>();

    public static Session addSession(Session session, String userIdentify) {
        sessionIdMap.put(session.getId(),userIdentify);
        return sessionMap.put(userIdentify, session);
    }

    public static void removeSession(Session session) {
        String identify = sessionIdMap.get(session.getId());
        sessionMap.remove(identify);
    }

    public static List<Session> getSessionList() {
        return new ArrayList<>(sessionMap.values());
    }



}
